
package com.ifcar.app.view;

import com.ifcar.app.util.ThemeSettingsHelper;

import android.content.Context;
import android.graphics.Canvas;
import android.util.AttributeSet;
import android.widget.ImageView;

public class MyImageView extends ImageView {

    public MyImageView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public MyImageView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyImageView(Context context) {
        super(context);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        onDrawExtra(canvas);

    }

    protected void onDrawExtra(Canvas canvas) {
        if (ThemeSettingsHelper.getThemeSettingsHelper(getContext()).isNightTheme(getContext())) {
            canvas.save();
            final int left = getLeft();
            final int right = getRight();
            final int top = getTop();
            final int bottom = getBottom();

            final int paddingLeft = getPaddingLeft();
            final int paddingRight = getPaddingRight();
            final int paddingTop = getPaddingTop();
            final int paddingBottom = getPaddingBottom();

            final int scrollX = getScrollX();
            final int scrollY = getScrollY();

            canvas.clipRect(scrollX + paddingLeft, scrollY + paddingTop, scrollX + right - left
                    - paddingRight, scrollY + bottom - top - paddingBottom);

            canvas.translate(paddingLeft, paddingTop);
            canvas.drawARGB(125, 0, 0, 0);
            canvas.restore();
        }
    }
}
